//
//  ImageViewCell.m
//  ASI
//
//  Created by Shi Zijie on 12-3-13.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ImageViewCell.h"

@implementation UITextField(UITextFieldLogin)
- (CGRect)textRectForBounds:(CGRect)bounds {
    CGRect inset = CGRectMake(bounds.origin.x + 10, bounds.origin.y, bounds.size.width - 10, bounds.size.height);
    return inset;
}
- (CGRect)editingRectForBounds:(CGRect)bounds {
    CGRect inset = CGRectMake(bounds.origin.x + 10, bounds.origin.y, bounds.size.width - 30, bounds.size.height);
    return inset;
}
@end

@implementation ImageViewCell
@synthesize userImageView;
@synthesize tripImageView;
@synthesize delegate;
@synthesize m_index;


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        userImageView = [[EGOImageView alloc] initWithFrame:
                     CGRectMake(0, 0, 48, 48)];
        //userImageView.image = [UIImage imageNamed:@"bg_user_default.png"];
        [userImageView setPlaceholderImage:[UIImage imageNamed:@"bg_user_default.png"]];
        [self addSubview:userImageView];
        
        tripImageView = [[EGOImageView alloc] initWithFrame:
                         CGRectMake(48, 0, frame.size.width-48, 48)];
        //tripImageView.image = [UIImage imageNamed:@"bg_trip_default.png"];
        [tripImageView setPlaceholderImage:[UIImage imageNamed:@"bg_trip_default.png"]];
        [self addSubview:tripImageView];
        
        creattimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 52, 48, 16)];
        creattimeLabel.text = @"2012-03-12";
        creattimeLabel.backgroundColor = [UIColor clearColor]; 
        //creattimeLabel.textColor = [UIColor blackColor];
        creattimeLabel.font = [UIFont systemFontOfSize:9.0f];
        creattimeLabel.numberOfLines = 0;
        creattimeLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:creattimeLabel];
        
        nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 80, 16)];
        nameLabel.text = @"浪漫之旅";
        nameLabel.backgroundColor = [UIColor clearColor]; 
        //nameLabel.textColor = [UIColor blackColor];
        nameLabel.font = [UIFont systemFontOfSize:12.0f];
        nameLabel.numberOfLines = 0;
        nameLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:nameLabel];
        
        likeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(frame.size.width-80, 52, 15, 16)];
        likeImageView.image = [UIImage imageNamed:@"icn_like.png"];
        [self addSubview:likeImageView];
        
        likeCount = [[UILabel alloc]initWithFrame:CGRectMake(frame.size.width-63, 52, 15, 16)];
        likeCount.text = @"0";
        likeCount.backgroundColor = [UIColor clearColor]; 
        //likeCount.textColor = [UIColor blackColor];
        likeCount.font = [UIFont systemFontOfSize:12.0f];
        likeCount.numberOfLines = 0;
        likeCount.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:likeCount];
        
        collectImageView = [[UIImageView alloc] initWithFrame:CGRectMake(frame.size.width-30, 52, 15, 16)];
        collectImageView.image = [UIImage imageNamed:@"icn_collect.png"];
        [self addSubview:collectImageView];
        
        collectCount = [[UILabel alloc]initWithFrame:CGRectMake(frame.size.width-13, 52, 15, 16)];
        collectCount.text = @"0";
        collectCount.backgroundColor = [UIColor clearColor]; 
        //collectCount.textColor = [UIColor blackColor];
        collectCount.font = [UIFont systemFontOfSize:12.0f];
        collectCount.numberOfLines = 0;
        collectCount.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:collectCount];
        
        [self setUserInteractionEnabled:YES];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)setImageViewCell:(TripInfo*) info
{
    [userImageView setImageURL:[NSURL URLWithString:info.memberid]];
    [tripImageView setImageURL:[NSURL URLWithString:info.coverurl]];
    
    creattimeLabel.text = info.creattime;
    nameLabel.text = info.name;
    likeCount.text = info.favorcount;
    collectCount.text = info.praisecount;
    
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //[super touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesEnded");
    [super touchesEnded:touches withEvent:event];
    [delegate touchUpInsideImageViewCell:m_index];
}

- (void)dealloc {
    [userImageView release]; userImageView = nil;
    [tripImageView release]; tripImageView = nil;
    [super dealloc];
}

@end
